import sys
from PySide import QtGui, QtCore

class MessageBoxes(QtGui.QWidget):

    def __init__(self):
        super(MessageBoxes, self).__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(200, 100, 400, 400)
        self.setWindowTitle("MessageBoxes")

        btnQuit = QtGui.QPushButton("Quit", self)
        btnQuit.clicked.connect(QtCore.QCoreApplication.instance().quit)
        btnQuit.resize(btnQuit.sizeHint())
        btnQuit.move(50, 50)

        #btnShowMsgBox = QtGui.QPushButton("ShowMsgBox", self)
        #btnShowMsgBox.clicked.connect()
        #btnShowMsgBox.resize(btnShowMsgBox.sizeHint())
        #btnShowMsgBox.move(50, 80)

        self.show()

    def closeEvent(self, event):
        msgBoxReply = QtGui.QMessageBox.question(self, "Message", "Are you sure",
                                                 QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                                                 QtGui.QMessageBox.No)
        if msgBoxReply == QtGui.QMessageBox.Yes:
            print("You pressed yes")
            event.accept()
        else:
            print("You press no")
            event.ignore()


def main():
    appObject = QtGui.QApplication(sys.argv)
    mainWindow = MessageBoxes()
    sys.exit(appObject.exec_())

if __name__ == '__main__':
    main()